package com.anlu.cloud.firstekserviceinvoker.Controller;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.awt.*;


@Configuration
@RestController
public class InvokerController {

    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    @RequestMapping(value = "/router", method = RequestMethod.GET)
    public String router() {
        RestTemplate restTpl = getRestTemplate();
        // 根据应用名称调用服务
//        String json = restTpl.getForObject(
//                "http://first-service-provider/person/1", String.class);

        String json = restTpl.getForObject(
                "http://first-cloud-provider/person/1", String.class);
        return json;
    }
}
